<?php

namespace App\Console\Commands\SiteLocation;

use App\Console\Commands\Poi\BusinessPoi;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Models\Wanggui\CustomerDepartmentTaskModel;
use App\Service\Common\AreaService;
use App\Service\OpenShop\Merchant\SiteLocationPushMsgService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class SiteLocationPushMsgTestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'siteLocation:confirm:push-msg-test {orderNo}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '选址确认消息推送测试';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $merchantConfirmTime = time();
        $orderNo              = $this->argument('orderNo');

        $siteLocationModel = OpenShopSiteLocationModel::query()->whereIn('source',
            [
                OpenShopSiteLocationModel::SOURCE_OPEN_SHOP,
                OpenShopSiteLocationModel::SOURCE_HOUSING
            ])->where('orderNo', $orderNo)->first();

        //发送确址信息
        try {
            $shopCode = (int)optional($siteLocationModel->signOrderRel)->shopCode;

            SiteLocationPushMsgService::getCardMsg($orderNo, $siteLocationModel, $merchantConfirmTime, $shopCode);

        } catch (\Exception|GuzzleException $exception) {
            Log::info("test 选址确认机器人推送出错： " . $exception->getMessage());
        }
    }
}
